package com.dingding.service.account.core.tailwind.dao.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.Depositdetail;
import com.dingding.common.core.beans.Useraccount;
import com.dingding.service.account.core.tailwind.dao.ITailwindUserAccountDao;
import com.dingding.service.account.core.tailwind.sql.UserAccountSQL;

/**
 * 
 * @ClassName: UserAccountDaoImpl 
 * @Description: 用户账户DAO接口实现类(乘客端)
 * @author YHQ
 * @date 2016年12月26日 下午5:37:06
 * @since V2.6.3
 * 
 */
@Component("tailwindUserAccountDao")
public class TailwindUserAccountDaoImpl implements ITailwindUserAccountDao{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	/**
	 * 
	 * @Title: getUserAccountById 
	 * @Description: 根据用户Id获取用户账户信息(乘客端)
	 * @param userId 用户Id
	 * @author YHQ 
	 * @return Useraccount    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public Useraccount getUserAccountById(String userId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(Useraccount.class, UserAccountSQL.GET_USER_ACCOUNT, userId);
		} catch (Exception e) {
			log.error("根据用户Id获取用户账户信息(乘客端)时出现异常   类：" + this.getClass() + " getUserAccountById()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: updateUserAccount 
	 * @Description: 修改用户账户信息
	 * @param useraccount 要修改的用户账户信息
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean updateUserAccount(Useraccount useraccount) {
		
		try {
			baseDaoX.update(useraccount);
			return true;
		} catch (Exception e) {
			log.error("修改用户账户信息时出现异常   类： " + this.getClass() + " updateUserAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: addDepositDetail 
	 * @Description: 增加提现明细(顺风车端)
	 * @param depositdetail 提现信息
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addDepositDetail(Depositdetail depositdetail) {
		
		try {
			baseDaoX.save(depositdetail);
			return true;
		} catch (Exception e) {
			log.error("增加提现明细(顺风车端)时出现异常   类： " + this.getClass() + " addDepositDetail()", e);
		}
		
		return false;
	}

	
	
}
